<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        var a = '123';
        console.log(typeof a);
        console.log(a);
        /*
        1 使用 Number函数  如果是纯数字，则转为数字，
        2 如果函数字母，符号，则转为NAN
        3 如果是空格，或全是空格，则转为0

        布尔-->数字
         true  转成1
         false 转成0

         null ->数字  0
         undefined ->数字  NaN


        
        另外一种方式
        ParseInt 将字符串中的有效整数转为int类型
        ParseFloat  将字符串中的有效整数转为Float类型
        */
        a = Number(a);
        console.log(typeof a);
        console.log(a);

        var b = '123a';
        b = Number(b);
        console.log(typeof b);
        console.log(b); 

        var c = '123abc';
        c = parseInt(c);
        console.log(typeof c);
        console.log(c);

        var d = '123';
        d = parseFloat(d);
        console.log(typeof d);
        console.log(d);

        var e = '';
        e = parseFloat(e);
        console.log(typeof e);
        console.log(e);

        var f = true;
        f = Number(f);
        console.log(typeof f);
        console.log(f);

        var g = null;
        g = Number(g);
        console.log(typeof g);
        console.log(g);

        var h = undefined;
        h = Number(h);
        console.log(typeof h);
        console.log(h);


        var i = "123px";
        i = parseInt(i);
        console.log(typeof i);
        console.log(i);

        var j = "123.3px";
        j = parseFloat(j);
        console.log(typeof j);
        console.log(j);


         




    </script>
</head>
<body>
    
</body>
</html>